﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SmartWeb.BLL;

public partial class Task_WorkTask_WorkTaskEdit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            Bind();
    }
    private void Bind()
    {
        BindYearList();
        for (int i = 1; i <= 12; i++)
        {
            this.DptMonth.Items.Add(new ListItem(i.ToString() + "月", i.ToString()));
        }

        this.DptYear.SelectedValue = DateTime.Now.Year.ToString();
        this.DptMonth.SelectedValue = DateTime.Now.Month.ToString();

        if (Request["ID"] == null)
            return;
        for (int i = 0; i < 20; i++)
        {
            this.DptOrderID.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }

        Yipusoft.WorkTaskGrade.Model.WorkTaskGradeInfo model = new Yipusoft.WorkTaskGrade.BLL.WorkTaskGrade().GetDetail(new Guid(Request["ID"]));
        if (model == null)
            return;
        this.DptYear.SelectedValue = model.TaskDate.Year.ToString();
        this.DptMonth.SelectedValue = model.TaskDate.Month.ToString();
        this.txtWorkTask.Text = UserFun.HtmlToText(model.WorkTask);
        this.txtMarking.Text = model.Marking.ToString();
        this.txtCompleteCircs.Text = UserFun.HtmlToText(model.CompleteCircs);
        this.txtSimpleCircs.Text = UserFun.HtmlToText(model.SimpleCircs);
        this.txtReMark.Text = model.ReMark;
        this.DptOrderID.SelectedValue = model.OrderID.ToString();
        this.txtScore.Text = model.SelfScore == -1 ? "" : model.SelfScore.ToString("0.00");
        if (Request["P"] != null)
        {
            Caption.Text = "填写任务及评分";
            DptMonth.Enabled = false;
            DptYear.Enabled = false;
            txtWorkTask.Enabled = false;
            txtMarking.Enabled = false;
        }
        else
        {
            Caption.Text = "修改任务";
        }
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        lblpromt.Text = "";
        Yipusoft.WorkTaskGrade.Model.WorkTaskGradeInfo model = new Yipusoft.WorkTaskGrade.BLL.WorkTaskGrade().GetDetail(new Guid(Request["ID"]));
        if (model == null)
            return;
        model.CompleteCircs = UserFun.TextToHtml(txtCompleteCircs.Text);
        model.CreateUserID = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).UserID;
        model.DepartmentID = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
        model.LastModifyDate = DateTime.Now;
        model.Marking = decimal.Parse(txtMarking.Text.Trim());
        model.ReMark = txtReMark.Text;
        model.TaskDate = Convert.ToDateTime(Convert.ToDateTime(DptYear.SelectedValue + "-" + DptMonth.SelectedValue + "-1"));
        model.WorkTask = UserFun.TextToHtml(txtWorkTask.Text);
        model.OrderID = int.Parse(this.DptOrderID.SelectedValue);
        model.SelfScore = txtScore.Text == "" ? -1 : Convert.ToDecimal(txtScore.Text);
        model.SimpleCircs = txtSimpleCircs.Text;
        model.Id = new Guid(Request["ID"]);
        if (new Yipusoft.WorkTaskGrade.BLL.WorkTaskGrade().Update(model))
        {
            lblpromt.Text = "修改成功";
        }
        else
        {
            lblpromt.Text = "操作失败";
        }

    }

    private void BindYearList()
    {
        for (int i = 2008; i <= 2050; i++)
        {
            ListItem li = new ListItem();
            li.Text = i.ToString() + "年";
            li.Value = i.ToString();
            DptYear.Items.Add(li);
        }
    }
}
